package com.worker.microsoft.controller;

import com.onedec.admin.entity.OnedecEmp;
import com.worker.microsoft.service.*;
import com.worker.microsoft.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("emp")
public class EmpController {
    @Autowired
    private DeptService deptService;
    @Autowired
    private RoleService roleService;
    @Autowired
    private EmpService empService;

    @RequestMapping("selectAllDept")
    public Result selectAllDept() throws Exception {
        return new Result("200", "success", null, deptService.selectAll());
    }

    @RequestMapping("selectAllRole")
    public Result selectAllRole() throws Exception {
        return new Result("200", "success", null, roleService.selectAll());
    }

    @Resource
    private FriendService friendService;
    @Resource
    private MsgGroupEmpService msgGroupEmpService;

    @RequestMapping("addEmp")
    public Result addEmp(OnedecEmp onedecEmp) throws Exception {
        String empIdnum = Integer.toString((int) ((Math.random() * 9 + 1) * 100000));
        onedecEmp.setEmpIdnum(empIdnum);
        empService.insert(onedecEmp);
        friendService.insertFriendGroup(onedecEmp.getEmpId());
        msgGroupEmpService.insertEmpGroup(1, onedecEmp.getEmpId());
        msgGroupEmpService.insertEmpGroup(onedecEmp.getEmpDid(), onedecEmp.getEmpId());

        return new Result("200", "success", onedecEmp.getEmpId(), null);
    }
}
